package com.jt.tenant.conn;

import com.jt.tenant.app.JTApplication;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by AD on 2016/5/12.
 */
@HttpInlet(Conn.INLET_GET_CAR_BRAND)
public class GetCarBrand extends JTAsyGet<GetCarBrand.Info> {
    public String token = JTApplication.jtPreferences.readToken();

    public GetCarBrand(AsyCallBack<Info> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected Info parser(JSONObject object) {
        JSONObject apiTYF = object.optJSONObject("apiTYF");

        JSONObject head = apiTYF.optJSONObject("head");

        Info info = new Info();

        info.msg = head.optString("msg");

        info.code = head.optString("code");

        JSONObject body = apiTYF.optJSONObject("body");

        JSONArray cblist = body.optJSONArray("list");

        if(cblist!=null){
            for (int i=0;i<cblist.length();i++){
                JSONObject object_cb = cblist.optJSONObject(i);
                CBList mList = new CBList();
                mList.ID = object_cb.optString("id");
                mList.NAME = object_cb.optString("name");
                mList.LETTER = object_cb.optString("letter");

                info.cbLists.add(mList);
            }
        }else{
            TOAST = "未能获取车辆品牌信息，请稍后重试";
        }
        return info;
    }

    public static class Info{
        public String msg;
        public String code;
        public List<CBList> cbLists = new ArrayList<>();

    }
    public static class CBList implements Serializable{
        public String  ID,NAME,LETTER;
    }
}
